fromJSON("https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&=1581615429898") %>%
.$data %>%
writeLines(file.path('real_json'))
cov_data = fromJSON(file.path('real_json'))
china_total = cov_data$chinaTotal %>% as_tibble()
china_add = cov_data$chinaAdd %>% as_tibble()
day_list = cov_data$chinaDayList
day_add_list = cov_data$chinaDayAddList
date(cov_data$lastUpdateTime)
## [1] "2020-02-14"
Add summary for every day
daily_summary = paste0("Due ",date(cov_data$lastUpdateTime),", confirmed: ",china_total$confirm," suspected: ",china_total$suspect)
daily_summary
## [1] "Due 2020-02-14, confirmed: 63935 suspected: 10109"
total_daily_ggplot =
day_list %>%
mutate(date = ymd(paste0("2020.",date))) %>%
select(date,confirm,dead, heal, suspect) %>%
gather(key='type',value = 'count',confirm:suspect) %>%
ggplot(aes(x = date, y = count,color =type))+
geom_line()+
geom_point()+
theme_classic()+
labs(
title = "Total Count of NCODIV-19",
caption = daily_summary
)
ggplotly(total_daily_ggplot)
add_daily_ggplot =
day_add_list %>%
mutate(date = ymd(paste0("2020.",date))) %>%
select(date,confirm,dead, heal, suspect) %>%
gather(key='type',value = 'count',confirm:suspect) %>%
ggplot(aes(x = date, y = count,color =type))+
geom_line()+
geom_point()+
theme_classic()+
labs(
title = "Total Count of NCODIV-19",
subtitle = daily_summary
)
ggplotly(add_daily_ggplot)
a = cov_data$areaTree %>% pull(children)
province_names = a[1][[1]]$name
province_data = a[1][[1]]$total
add_province = function(df){
rownames(df) = province_names
df =
df %>%
rownames_to_column('name')
return(df %>% as_tibble())
}
province_daily_count = add_province(province_data)
province_daily_count$name=fct_reorder(province_daily_count$name,province_daily_count$confirm)
ggplot(province_daily_count, aes(x=name, y=confirm)) +
geom_col(fill='steelblue')+coord_flip()+
geom_text(aes(y=confirm,label=confirm,hjust=0))+
theme_classic()
mapdata = read_sf("chinamap/中国省界.shp") %>%
janitor::clean_names()
prov_map_data = inner_join(mapdata,province_daily_count,by='name')
## Warning: Column `name` joining character vector and factor, coercing into
## character vector
prov_daily_map =
ggplot(prov_map_data) +
geom_sf(aes(fill = log10(confirm)),alpha =.8) +
theme_bw() +
worldtilegrid::theme_enhance_wtg()+
viridis::scale_fill_viridis()+
labs(
title = "Data map of NCodiv-19 confirmed people in China",
subtitle = daily_summary
)+
theme(axis.ticks = element_blank(),rect = element_blank())
ggplotly(prov_daily_map)